package com.hx.company.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.hx.company.dao.UserDao;
import com.hx.company.vo.Merchant;
import com.hx.company.vo.Order;
import com.hx.company.vo.User;
import com.hx.company.vo.UserLogin;
@Repository("ud")
public class UserDaoImpl implements UserDao {
	@PersistenceContext(name="mn")
	private EntityManager em;
	
	@Override
	public int addUser(User u, UserLogin ul) {
		
		em.persist(u);
		em.persist(ul);
		System.out.println(u.toString()+"---"+ul.toString());
		return u.getUphone().length();
	}

	@Override
	public List<UserLogin> find(UserLogin ul) {
		String s="select c from UserLogin c where c.uphone=:uphone";
		List<UserLogin> cs=em.createQuery(s)
				.setParameter("uphone", ul.getUphone())
				.getResultList();
		
		
		return cs;
	}

	@Override
	public List<Merchant> findAll() {
		String s="select m from Merchant m where m.temp=1";
		List<Merchant> cs=em.createQuery(s)
				.getResultList();
		
		return cs;
	}

	@Override
	public Boolean addOrder(Order o) {
		em.persist(o);
		
		return true;
	}

}
